using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Zsa.Reflection.Discovery
{
    /// <summary>
    /// 
    /// </summary>
    public class ActivationPropertyAttribute : ActivationInstanceBaseAttribute
    {
        #region Fields
        /// <summary>
        /// The index argument.
        /// </summary>
        private string _PropertyName;

        /// <summary>
        /// The argument value.
        /// </summary>
        private string _Value;

        /// <summary>
        /// The argument type.
        /// </summary>
        private Type _ArgumentType;

        /// <summary>
        /// The type convertor type used to convert the string 
        /// type to its value.
        /// </summary>
        private Type _TypeConvertorType;
        #endregion Fields

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="ActivationArgumentAttribute"/> class.
        /// </summary>
        /// <param name="instanceName">Name of the instance.</param>
        /// <param name="instanceType">Type of the instance.</param>
        /// <param name="argumentIndex">Index of the argument.</param>
        /// <param name="value">The value.</param>
        public ActivationPropertyAttribute(string instanceName, Type instanceType,
            string propertyName, int value)
            : this(instanceName, instanceType, propertyName,
            value.ToString(), typeof(int), typeof(Int32Converter), true)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ActivationArgumentAttribute"/> class.
        /// </summary>
        /// <param name="instanceName">Name of the instance.</param>
        /// <param name="instanceType">Type of the instance.</param>
        /// <param name="argumentIndex">Index of the argument.</param>
        /// <param name="value">The value.</param>
        public ActivationPropertyAttribute(string instanceName, Type instanceType,
            string propertyName, long value)
            : this(instanceName, instanceType, propertyName,
            value.ToString(), typeof(long), typeof(System.ComponentModel.Int64Converter), true)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ActivationArgumentAttribute"/> class.
        /// </summary>
        /// <param name="instanceName">Name of the instance.</param>
        /// <param name="instanceType">Type of the instance.</param>
        /// <param name="argumentIndex">Index of the argument.</param>
        /// <param name="value">The value.</param>
        public ActivationPropertyAttribute(string instanceName, Type instanceType,
            string propertyName, string value)
            : this(instanceName, instanceType, propertyName,
            value.ToString(), typeof(string), typeof(StringConverter), true)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ActivationArgumentAttribute"/> class.
        /// </summary>
        /// <param name="instanceName">Name of the instance.</param>
        /// <param name="instanceType">Type of the instance.</param>
        /// <param name="argumentIndex">Index of the argument.</param>
        /// <param name="value">The value.</param>
        /// <param name="argumentType">Type of the argument.</param>
        /// <param name="typeConvertor">The type convertor.</param>
        /// <param name="allowConfig">if set to <c>true</c> [allow config].</param>
        public ActivationPropertyAttribute(string instanceName, Type instanceType,
            string propertyName, string value, Type argumentType, Type typeConvertor, bool allowConfig)
            : base ( instanceName, instanceType, ActivationAttributeType.Constructor, allowConfig)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName", "The propertyName argument cannot be null !");
            }
            if (propertyName == string.Empty)
            {
                throw new ArgumentNullException("propertyName", "The propertyName argument cannot be a am empty string !");
            }
            if (argumentType == null)
            {
                throw new ArgumentNullException("argumentType", "The argumentType argument cannot be null !");
            }
            _PropertyName = propertyName;
            _Value = value;
            _ArgumentType = argumentType;
            _TypeConvertorType = typeConvertor;
        }
        #endregion Constructor

        #region Properties
        /// <summary>
        /// Gets the name of the property.
        /// </summary>
        /// <value>The name of the property.</value>
        public string PropertyName
        {
            get
            {
                return _PropertyName;
            }
        }

        /// <summary>
        /// Gets the type of the argument.
        /// </summary>
        /// <value>The type of the argument.</value>
        public Type ArgumentType
        {
            get
            {
                return _ArgumentType;
            }
        }

        /// <summary>
        /// Gets the type of the type convertor.
        /// </summary>
        /// <value>The type of the type convertor.</value>
        public Type TypeConvertorType
        {
            get {
                return _TypeConvertorType;
            }
        }


        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <value>The value.</value>
        public string Value
        {
            get
            {
                return _Value;
            }
        }

        #endregion Properties
    }
}
